package agenda;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Eventos.java
 *
 * Created on 10/11/2011, 21:47:27
 */

/**
 *
 * @author Brenno
 */
public class JanelaPesquisaEventoData extends javax.swing.JFrame {

    /** Creates new form Eventos */
    public JanelaPesquisaEventoData(String Data) {
        this.Data = Data;
    	initComponents();
        setDefaultCloseOperation(HIDE_ON_CLOSE);
        setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
        setTitle("Eventos");
        this.setLocationRelativeTo(null);  
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        Eventos = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 3, 36)); // NOI18N
        jLabel1.setText("Eventos");
        CarregaEventos();
		Eventos.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				new JanelaEvento(Agenda.Eventos.get(Integer.parseInt((String)Eventos.getValueAt(Eventos.getSelectedRow(),0)))).setVisible(true);
				setVisible(false);
				dispose();
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
        Eventos.setAutoscrolls(false);
        Eventos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(Eventos);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(138, 138, 138)
                .addComponent(jLabel1))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>

    // Variables declaration - do not modify
    private static javax.swing.JTable Eventos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private static String Data;
    // End of variables declaration
    static void CarregaEventos(){
    	Eventos.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                },
                new String [] {
                    "Posição","Nome", "Data", "Horário", "Duração"
                }
            ) {
                boolean[] canEdit = new boolean [] {
                    false, false, false, false
                };

                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
                }
            });
    		DefaultTableModel modelo = (DefaultTableModel) Eventos.getModel();
    		for(int i=0;i<Agenda.Eventos.size();i++){
    			int dia = Integer.parseInt(Agenda.Eventos.get(i).getData().substring(0, 2));
    			int mes = Integer.parseInt(Agenda.Eventos.get(i).getData().substring(3, 5));
    			int ano = Integer.parseInt(Agenda.Eventos.get(i).getData().substring(6, 10));
    			int dia2 = Integer.parseInt(Data.substring(0, 2));
    			int mes2 = Integer.parseInt(Data.substring(3, 5));
    			int ano2 = Integer.parseInt(Data.substring(6, 10));
    			if(dia == Integer.parseInt(Data.substring(0, 2)) && mes ==Integer.parseInt(Data.substring(3, 5)) && ano == Integer.parseInt(Data.substring(6, 10))){
    				modelo.addRow(new String[]{i+"",Agenda.Eventos.get(i).getNome(),Agenda.Eventos.get(i).getData(),Agenda.Eventos.get(i).getHorario(),Agenda.Eventos.get(i).getDuracao(),Agenda.Eventos.get(i).getDescricao()});
    			}
    		}
    }
}
